<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <title>Add Model</title>
</head>
<body>
    <script type="text/javascript">
        function addModel() {
            var modelName = document.getElementById("modelNameInput").value;
            var systemSelect = document.getElementById("systemSelect");
            var systemIndex = systemSelect.selectedIndex;
            var systemText = systemSelect.options[systemIndex].value;
            console.log(modelName,systemSelect);
            //请求参数
            var list = {
                "modelName": modelName,
                "systemID": systemText
            };
            console.log(list);
            //
            $.ajax({
                //请求方式
                type : "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url : "http://127.0.0.1:8888/uitest/models/add",
                //数据，json字符串
                data : JSON.stringify(list),
                //请求成功
                success : function(result) {
                    console.log("result");
                    console.log(result);
                    console.log("resultEnd");
                    window.location="http://127.0.0.1:8888/uitest/modelsPage";
                },
                //请求失败，包含具体的错误信息
                error : function(e){
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });
        }
    
        function deleteModel() {
            var cellId = $(node).parent().parent().find(".aftdis");        		   		
            pppp.css("display","none");
        }

        window.onload = function getSystem(){
            //请求参数
            var list = {};
            console.log(list);
            //
            $.ajax({
                //请求方式
                type : "GET",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url : "http://127.0.0.1:8888/uitest/systems",
                //数据，json字符串
                data : JSON.stringify(list),
                //请求成功
                success : function(result) {
                    console.log("result");
                    console.log(result);
                    console.log("resultEnd");

                    result.forEach(systemNameDic => {
                        var systemId = systemNameDic.id;
                        var systemName = systemNameDic.system_name;
                        document.getElementById("systemSelect").options.add(new Option(systemName,systemId));
                    });
                },
                //请求失败，包含具体的错误信息
                error : function(e){
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });
        }
    </script>
<div>
    <div style="text-align: center;">
        <h1>Add Model</h3>
    </div>
	<div id="modelName" style="text-align:left; margin-top: 50px; margin-left: 15%">
		Model Name:<input id="modelNameInput" type="text" size="50px" name="modelName" placeholder="Please input modelName with string" />
    </div>
    <div id="system" style="text-align:left; margin-top: 50px; margin-left: 15%">
		Model System:<select id="systemSelect">
            <!-- <option value="erp">ERP</operation>
            <option value="sellerCenter">Seller Center</operation>
            <option value="repair">Repair</operation>
            <option value="insuranceSystem">Insurance System</operation> -->
        </select>
    </div>
    <div id="addBtn" style="text-align:left; margin-top: 50px; margin-left: 15%">
		<button type="button" onclick="addModel()">Confirm</button>
    </div>
</div>

</body>
</html>